package code.juc.stream;

import java.io.IOException;
import java.io.PipedReader;

/**
 * 读取数据
 */
public class ReadData {

    public void readData(PipedReader in) {
        System.out.println("read:");
        char[] array = new char[20];
        try {
            int readLength = in.read(array);
            while (readLength != -1) {
                String data = new String(array, 0, readLength);
                System.out.print(data);
                readLength = in.read(array);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
